<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>班组修改</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../js/formSelects/formSelects-v4.css" media="all">
    <link rel="stylesheet" href="../css/font/iconfont.css" media="all">

    <style>
        .other_name {
            display: inline-block;
            margin-right: 10px;
            cursor: pointer;
        }
        .other_name>i {
            margin-left: 5px;
        }
        .other_name>i:hover {
            color: #FFFFFF;
        }

        .layui-form-label{
            width:140px;
        }
        .layui-input-block{
            margin-left: 170px;
        }
        a{
            color:#fff;
        }
        a:hover {
            color: #00c0ef;
        }
    </style>
</head>
<body>


<div style="margin-top: 40px; margin-right: 30px;">
    <form class="layui-form" action=""  lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>班组名称</label>
            <div class="layui-input-block">
                <input type="text" name="banzu_name" id="banzu_name"  lay-verify="required" readonly placeholder="人员数量" class="layui-input" style="background-color:#C0C0C0 ">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>工种</label>
            <div class="layui-input-block">
                <select name="profession"  id="profession" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">涉及人员</label>
            <div class="layui-input-block">
                <select name="number"  id="number" xm-select="number" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>

        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">人员数量</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="text" name="number" id="number"  lay-verify="required|integer" placeholder="人员数量" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>班组负责人</label>
            <div class="layui-input-block">
                <input type="text" name="banzu_person"  id="banzu_person" lay-verify="required" placeholder="班组负责人" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>班组负责人电话</label>
            <div class="layui-input-block">
                <input type="text" name="banzu_person_phone"  id="banzu_person_phone"  lay-verify="required|phone" placeholder="班组负责人电话" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item" id="divSubmit">
            <div class="layui-input-block"  style="text-align: center;">
                <button id="btnSub" class="layui-btn" lay-filter="formSubmit"  lay-submit="">提交</button>
            </div>
        </div>

    </form>
</div>

</body>
<script src="../assets/layui/layui.js"></script>
<script src="../js/common.js"></script>
<script>
    layui.config({
        base: '../js/'
    }).extend({
        formSelects: 'formSelects/formSelects-v4'
    });
    var $;

    layui.use(['jquery','form','validate','common','element', 'laydate','upload','formSelects'], function () {
        var form = layui.form,
            layer = layui.layer,
            validate = layui.validate,
            formSelects = layui.formSelects,
            common = layui.common;
        $ = layui.jquery;

        validate.regVerify();
        common.initCommSelectData("#profession","../sys/dict/listMuti?ddtype=profession",false);
        var Id=common.getUrlParam("id");
        formSelects.config("number",{
            keyName: 'name',
            keyVal: 'code'})
            .data("number","server",{
                url: '../project/getperson',
                success: function(id, url, searchVal, result){
                    formSelects.value('number',result);
                }
            });
        form.render('select');
        formSelects.render();
        //        var op=common.getUrlParam("op");
       var name="";
        $.ajax({
            url: "../project/banzuinfo",
            dataType: "json",
            data: { Id: Id },
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    var data = rtn.data;
                    form.val('dataForm', {
                        banzu_name: data.banzu_name
                        , profession: data.profession
//                        , number: data.number
                        , banzu_person: data.banzu_person
                        , banzu_person_phone: data.banzu_person_phone
                    });
                    formSelects.value('number',data.number.split(','), true);
                    name=data.banzu_name;
                    $("#profession").find("option").each(function(){
                        if($(this).text()==rtn.data.profession){
                            $(this).attr('selected', 'selected');
                        }
                    });

                    form.render();
                }
            }
        });

        form.on('submit(formSubmit)', function (data) {
//            var banzu_name = $("#banzu_name").val();
            var profession = $("#profession").find("option:selected").val();
            var banzu_person = $("#banzu_person").val();
            var banzu_person_phone = $("#banzu_person_phone").val();
            if(profession=="请选择"||banzu_person==""||banzu_person_phone=="")
            {
                common.showError('必填项不能为空!');
            }
            var personid = formSelects.value('number', 'valStr');
            var profession_name = $("#profession").find("option:selected").text();

            data.field.banzu_name = name;
            data.field.profession = profession;
            data.field.banzu_person = banzu_person;
            data.field.banzu_person_phone = banzu_person_phone;
            data.field.number = personid;
            data.field.id = Id;
            data.field.profession_name = profession_name;
                $.ajax({
                    type: 'post',
                    url: '../project/banzuedit',
                    data: {json: JSON.stringify(data.field)},
                    success: function (rtn) {
                        if (rtn.code === 0) {  //数据保存成功
                            var msg = "保存成功!";
                            common.showInfo(msg, function () {
                                //刷新前页
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.document.getElementById('btnSearch').click();
                                parent.layer.close(index);
                            });
                        }
                        else {
                            common.showError(rtn.msg);
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        common.showError('保存错误');
                    }
                });
            return false;
        });

    })



</script>
</html>